# -*- coding:utf8 -*- #
# -----------------------------------------------------------------------------------
# ProjectName:   property-ui-auto-test
# FileName:     rights_p
# Author:      
# Datetime:    2022/9/26 17:50
# Description：权限配置-权限管理
# -----------------------------------------------------------------------------------
from time import sleep

from page.login_page import LoginPage


class RightsProfileGroup(LoginPage):
    def rights_profile_setup(self):
        # 展开菜单栏
        self.click('//*[@id="app"]/section/section/aside/div/img')
        sleep(1)
        # 展开菜单-权限配置
        self.click('//*[@id="app"]/section/section/aside/div/div/ul/li[7]/div')
        sleep(1)
        # 展开菜单-权限配置-权限管理
        self.click('//*[@id="app"]/section/section/aside/div/div/ul/li[7]/ul/li[1]/ul/li')

    # 修改角色
    def rights_profile_editPermissions(self, rolename='ui', optpwd='123123'):
        self.rights_profile_setup()
        # 点击修改按钮弹出编辑框
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[1]/div[2]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/span[2]/span[2]/button[2]/i')
        # 编辑页面传入角色名
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[1]/div/div/input',
            rolename)
        # 角色类型-打开选择框
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[2]/form/div[2]/div/div/div/input')
        sleep(0.5)
        # 选择角色并填充
        self.second_location("/html/body/div[3]/div[1]/div[1]/ul", 'li')
        # 点击提交按钮
        self.click('//*[@id="app"]/section/section/main/section/section/section/main/div[3]/div/div[3]/div/button[2]')
        # 输入操作密码
        self.send_keys('/html/body/div[3]/div/div[2]/div[2]/div[1]/input', optpwd)
        self.click('/html/body/div[3]/div/div[3]/button[2]')

    # 新增角色
    def rights_profile_addPermissions(self, rolename='ui-5', optpwd='123123'):
        '''
        :param rolename: 角色名
        :param optpwd: 操作密码
        :return:
        '''
        self.rights_profile_setup()
        # 权限管理页面-点击新增按钮
        self.click('//*[@id="app"]/section/section/main/section/section/section/header/button')
        # 新增页面传入角色名
        self.send_keys(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[4]/div/div[2]/form/div['
            '1]/div/div/input',
            rolename)
        # 角色类型-打开选择框
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[4]/div/div[2]/form/div[2]/div/div['
            '1]/div/input')
        sleep(0.5)
        # 选择角色并填充
        self.second_location("/html/body/div[3]/div[1]/div[1]/ul", 'li')
        # 点击提交按钮
        self.click('//*[@id="app"]/section/section/main/section/section/section/main/div[4]/div/div[3]/div/button[2]')
        # 输入操作密码
        self.send_keys('/html/body/div[3]/div/div[2]/div[2]/div[1]/input', optpwd)
        self.click('/html/body/div[3]/div/div[3]/button[2]')

    # 角色-权限配置
    def rights_profile_setPermissions(self, optpwd='123123'):
        '''

        :param optpwd: 操作密码
        :return:
        '''
        self.rights_profile_setup()
        # 选择角色，选择第一个并写死
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[1]/div[2]/div[1]/div[2]/div[1]/div['
            '2]/div[1]/div[1]/span[2]/span[1]')
        # 给角色勾选权限
        self.click('//*[@id="app"]/section/section/main/section/section/section/main/div[2]/div[2]/div/div[1]/div[1]')
        # 点击提交按钮
        self.click('//*[@id="app"]/section/section/main/section/section/section/main/div[2]/footer/button[2]')
        # 输入操作密码
        self.send_keys('/html/body/div[2]/div/div[2]/div[2]/div[1]/input', optpwd)
        self.click('/html/body/div[2]/div/div[3]/button[2]')

    # 删除角色
    def rights_profile_delPermissions(self, optpwd='123123'):
        self.rights_profile_setup()
        # 选择角色，选择第一个并写死
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[1]/div[2]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]')
        # 点击删除按钮
        self.click(
            '//*[@id="app"]/section/section/main/section/section/section/main/div[1]/div[2]/div[1]/div[2]/div[1]/div[2]/div[4]/div[1]/span[2]/span[2]/button[1]/i')
        # 输入操作密码
        self.send_keys('/html/body/div[2]/div/div[2]/div[2]/div[1]/input', optpwd)
        self.click('/html/body/div[2]/div/div[3]/button[2]')


if __name__ == '__main__':
    rp = RightsProfileGroup()
    rp.login()
    # rp.rights_profile_setup()
    # rp.rights_profile_addPermissions()
    rp.rights_profile_setPermissions()
    # rp.rights_profile_delPermissions()
    # rp.rights_profile_editPermissions()
    # rp.quit()
